package main;

import main.controller.actions.observer.ExitAction;

import javax.swing.*;
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class MainFrame extends JFrame {
    private static MainFrame instance;
    private JPanel contentPane;

    private BorderLayout borderLayout1 = new BorderLayout();
    private MainPanel mainPanel = new MainPanel();

    /**
     * @return the instance
     */
    public static MainFrame getInstance() {
        if (instance == null)
            instance = new MainFrame();
        return instance;
    }

    public void showErr(Object message) {
        JOptionPane.showMessageDialog(this, message, "Error", JOptionPane.ERROR_MESSAGE);
    }

    public void showErr(Exception message) {
        JOptionPane.showMessageDialog(this, message, "Error", JOptionPane.ERROR_MESSAGE);
    }

    public MainFrame() {
        super("Library GUI");
        instance = this;

        this.setLayout(borderLayout1);
        this.setSize(new Dimension(800, 600));
        this.setTitle("Photo Gallery Uploader");
        add(mainPanel, BorderLayout.CENTER);


        setLocation(200, 200);

        pack();
        setVisible(true);
        addWindowListener(new WindowAdapter() {

            @Override
            public void windowClosing(WindowEvent e) {
                ExitAction.getInstance().actionPerformed(null);
            }
        });


    }
}
